package ${packageName}.${controllerPath};

import com.dream21th.common.ComReq;
import com.dream21th.common.ComResp;
import com.dream21th.common.dto.PageDTO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Objects;
import ${packageName}.${entityPath}.${beanName?cap_first};
import ${packageName}.${servicePath}.${beanName?cap_first}Service;

/**
* @Desprition TODO
* @author ${author}
* @since ${(.now)?string('yyyy-MM-dd HH:mm:ss')}
*/
@RestController
@RequestMapping("/api/${beanName?uncap_first}")
public class ${beanName?cap_first}Controller {

    @Autowired
    private ${beanName?cap_first}Service ${beanName?uncap_first}Service;

    @PostMapping("/page")
    public ComResp<IPage<${beanName?cap_first}>> query${beanName?cap_first}Page(@RequestBody ComReq<PageDTO<${beanName?cap_first}>> req){
        LambdaQueryWrapper<${beanName?cap_first}> wrapper = Wrappers.<${beanName?cap_first}>lambdaQuery();
        wrapper.setEntity(req.getRequestData().getParam());
        IPage page = new Page<>(req.getRequestData().getCurrent(), req.getRequestData().getSize());
        return new ComResp<IPage<${beanName?cap_first}>>().data(${beanName?uncap_first}Service.page(page,wrapper)).success();
    }

    @PostMapping("/queryOne")
    public ComResp<${beanName?cap_first}> queryDictionaryOne(@RequestBody ComReq<${beanName?cap_first}> req){
    LambdaQueryWrapper<${beanName?cap_first}> wrapper = Wrappers.<${beanName?cap_first}>lambdaQuery();
        wrapper.setEntity(req.getRequestData());
        return new ComResp<${beanName?cap_first}>().data(${beanName?uncap_first}Service.getOne(wrapper)).success();
    }

    @PostMapping("/save")
    public ComResp saveDictionary(@RequestBody ComReq<${beanName?cap_first}> req){
        if(Objects.nonNull(req.getRequestData().getId())){
        ${beanName?uncap_first}Service.updateById(req.getRequestData());
        return new ComResp().success();
        }
        ${beanName?uncap_first}Service.save(req.getRequestData());
        return new ComResp().success();
    }

    @PostMapping("/delete")
    public ComResp<${beanName?cap_first}> delete(@RequestBody ComReq<List<Integer>> req){
        ${beanName?uncap_first}Service.removeByIds(req.getRequestData());
        return new ComResp().success();
    }
}

